<?php

namespace App\Models\Activity;

use App\Models\BaseModel;
use App\Models\Cruise\CruiseOrderModel;
use App\Models\Traits\KfSoftDeletes;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;

class ActivityModel extends BaseModel
{
    use HasFactory, KfUid, KfSoftDeletes;

    protected $table = "activity";

    protected $fillable = [
        "status",
        "updatedByUid",
        "updatedAt",
    ];

    /**
     * 活动类型
     */
    const ACTIVITY_TYPE_1    = 1;
    const ACTIVITY_TYPE_2    = 2;
    const ACTIVITY_TYPE_TEXT = [
        self::ACTIVITY_TYPE_1 => "品控服务项目(消杀活动)",
        self::ACTIVITY_TYPE_2 => "品牌运营项目"
    ];

    /**
     * 适用门店类型
     */
    const SHOP_TYPE_ALL  = 0;
    const SHOP_TYPE_PART = 1;
    const SHOP_TYPE_TEXT = [
        self::SHOP_TYPE_ALL  => "全部门店",
        self::SHOP_TYPE_PART => "部分门店",
    ];


    /**
     * 生效类型
     */
    const EXPIRE_TYPE_0    = 0;
    const EXPIRE_TYPE_1    = 1;
    const EXPIRE_TYPE_TEXT = [
        self::EXPIRE_TYPE_0 => "长期有效",
        self::EXPIRE_TYPE_1 => "限时生效",
    ];

    /**
     * 开关状态
     */
    const SWITCH_ON   = 1;
    const SWITCH_OFF  = 0;
    const SWITCH_TEXT = [
        self::SWITCH_ON  => "开启",
        self::SWITCH_OFF => "关闭",
    ];

    /**
     * 活动状态
     */
    const STATUS_0    = 0;
    const STATUS_1    = 1;
    const STATUS_2    = 2;
    const STATUS_3    = 3;
    const STATUS_TEXT = [
        self::STATUS_0 => "待发布",
        self::STATUS_1 => "正常",
        self::STATUS_2 => "暂停",
        self::STATUS_3 => "已结束",
    ];

    const JOIN_RESTRICT_1    = "noFirstOrder";
    const JOIN_RESTRICT_2    = "noLogisticsFile";
    const JOIN_RESTRICT_3    = "pauseShop";
    const JOIN_RESTRICT_4    = "closeShop";
    const JOIN_RESTRICT_5    = "prepareShop";
    const JOIN_RESTRICT_6    = "siteSelectionShop";
    const JOIN_RESTRICT_TEXT = [
        self::JOIN_RESTRICT_1 => "无首批订货",
        self::JOIN_RESTRICT_2 => "无物流建档",
        self::JOIN_RESTRICT_3 => "暂停营业门店",
        self::JOIN_RESTRICT_4 => "闭店门店",
        self::JOIN_RESTRICT_5 => "筹备门店",
        self::JOIN_RESTRICT_6 => "选址门店",
    ];

    /**
     * 导出业务类型
     */
    const BUSINESS_EXPORT_TYPE_0    = 0;
    const BUSINESS_EXPORT_TYPE_1    = 1;
    const BUSINESS_EXPORT_TYPE_2    = 2;
    const BUSINESS_EXPORT_TYPE_3    = 3;
    const BUSINESS_EXPORT_TYPE_4    = 4;
    const BUSINESS_EXPORT_TYPE_5    = 5;
    const BUSINESS_EXPORT_TYPE_6    = 6;
    const BUSINESS_EXPORT_TYPE_TEXT = [
        self::BUSINESS_EXPORT_TYPE_0 => "可参与门店",
        self::BUSINESS_EXPORT_TYPE_1 => "已参与门店",
        self::BUSINESS_EXPORT_TYPE_2 => "未参与门店",
        self::BUSINESS_EXPORT_TYPE_3 => "已传活动照片门店",
        self::BUSINESS_EXPORT_TYPE_4 => "未传活动照片门店",
        self::BUSINESS_EXPORT_TYPE_5 => "待审核门店",
        self::BUSINESS_EXPORT_TYPE_6 => "活动参与详情",
    ];

    /**
     * 霸屏弹窗频次
     */
    const SUPER_SCREEN_FREQUENCY_1    = 1;
    const SUPER_SCREEN_FREQUENCY_2    = 2;
    const SUPER_SCREEN_FREQUENCY_3    = 3;
    const SUPER_SCREEN_FREQUENCY_4    = 4;
    const SUPER_SCREEN_FREQUENCY_TEXT = [
        self::SUPER_SCREEN_FREQUENCY_1 => "不显示",
        self::SUPER_SCREEN_FREQUENCY_2 => "仅一次",
        self::SUPER_SCREEN_FREQUENCY_3 => "每天一次",
        self::SUPER_SCREEN_FREQUENCY_4 => "每次打开app",
    ];

    /**
     * 参与门店关联
     *
     * @return HasMany
     */
    public function shopRel(): HasMany
    {
        return $this->hasMany(ActivityShopRelModel::class, "activityId", "id");
    }

    /**
     * @return HasMany
     */
    public function shopActionRel(): HasMany
    {
        return $this->hasMany(ActivityActionModel::class, "activityId", "id")->orderBy("sort");
    }

    /**
     * @return HasMany
     */
    public function actionRel(): HasMany
    {
        return $this->hasMany(ActivityActionModel::class, "activityId", "id");
    }

    /**
     * @return HasMany
     */
    public function shopJoinRel(): HasMany
    {
        return $this->hasMany(ActivityShopJoinModel::class, "activityId", "id");
    }

    /**
     * @return HasMany
     */
    public function hasJoinShopRel(): HasMany
    {
        return $this->hasMany(ActivityShopJoinModel::class, "activityId", "id")
                    ->where("status", ActivityShopJoinModel::STATUS_3);
    }

    /**
     * @return HasMany
     */
    public function stayReviewJoinShopRel(): HasMany
    {
        return $this->hasMany(ActivityShopJoinModel::class, "activityId", "id")
                    ->where("status", ActivityShopJoinModel::STATUS_1);
    }

    /**
     * @return HasMany
     */
    public function shopJoinFeedbackRel(): HasMany
    {
        return $this->hasMany(ActivityShopJoinModel::class, "activityId", "id")
                    ->where("status", ActivityShopJoinModel::STATUS_3)
                    ->where("feedbackStatus", ActivityShopJoinModel::FEEDBACK_STATUS_1);
    }


}
